﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows.Controls;
using System.Globalization;
using System.Text.RegularExpressions;

namespace OCDP.Client.Resources.ValidationRules
{
    /// <summary>
    /// This class is used to validate input user data
    /// http://techfilth.blogspot.com/2011/07/taking-data-binding-validation-and-mvvm.html
    /// </summary>
    public class EmailValidationRule : ValidationRule
    {
        public override ValidationResult Validate(object value, CultureInfo cultureInfo)
        {
            string emailPattern = @"\w+([-+.']\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)*";
            Regex regex = new Regex(emailPattern, RegexOptions.None);
            if (regex.IsMatch(value.ToString()))                         
                return ValidationResult.ValidResult;
            else
                return new ValidationResult(false, "Email not valid");         
        }
    }
}
